package com.example.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/patient/user")  // 修改这里，避免和医生路径冲突
public class PatientUserController {

    @Autowired
    private UserService userService;

    /**
     * 根据 userId 获取患者信息
     */
    @GetMapping("/{userId}")
    public User getPatientByUserId(@PathVariable Integer userId) {
        QueryWrapper<User> query = new QueryWrapper<>();
        query.eq("id", userId);
        User patient = userService.getOne(query);
        if (patient == null) {
            throw new RuntimeException("未找到对应患者信息");
        }
        return patient;
    }
}
